import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:share_fit/app/components/back_btn_icon.dart';
import 'package:share_fit/app/controllers/device/device_const.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/tools/color_const.dart';
import 'package:share_fit/generated/locales.g.dart';
import 'package:sprintf/sprintf.dart';

import 'time_setting_logic.dart';

class TimeSettingPage extends StatelessWidget {
  TimeSettingPage({super.key});

  final logic = Get.put(TimeSettingLogic());
  final state = Get.find<TimeSettingLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(LocaleKeys.settings_time.ts),
        centerTitle: true,
        leading: BackBtnIcon(onTap: () => Get.back())
      ),
      body: Padding(
        padding: EdgeInsets.only(left: 40.w, top: 80.h, right: 40.w),
        child: ListView(
          children: [
            Container(
              height: 175.h,
              padding: EdgeInsets.only(left: 59.w, right: 36.w),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(20),
              ),
              child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text(
                      LocaleKeys.settings_time_sync.ts,
                      style: TextStyle(
                          fontSize: 42.sp,
                          color: ColorConst.primaryFontColor),
                    ),
                    Transform.scale(
                        scale: 0.7,
                        child: Obx(() => CupertinoSwitch(
                            value: state.isTimeSyncEnable.value,
                            activeColor: ColorConst.accentColor,
                            onChanged: (value) {
                              logic.setTimeSyncEnable(value);
                            }))
                    ),
                  ]),
            ),
            SizedBox(height: 75.h),
            /// sdk不支持，先屏蔽
            // _buildWorldTimeWidget(context)
          ],
        ),
      ),
    );
  }

  Widget _buildWorldTimeWidget(BuildContext context) {
    return Ink(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(20),
      ),
      child: InkResponse(
        splashColor: ColorConst.activeColor,
        borderRadius: BorderRadius.circular(8),
        highlightShape: BoxShape.rectangle,
        highlightColor: ColorConst.activeColor,
        containedInkWell: true,
        child: Container(
          height: 247.h,
          padding:
          EdgeInsets.only(left: 59.w, right: 36.w),
          child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  LocaleKeys.settings_world_time.ts,
                  style: TextStyle(
                      fontSize: 42.sp,
                      color: ColorConst.primaryFontColor),
                ),
                Expanded(child: Container()),
                Obx(() => Text(
                  sprintf(LocaleKeys.settings_start_time_morning.ts,
                      [state.time.value]),
                  style: TextStyle(
                      fontSize: 42.sp,
                      color: ColorConst.primaryFontColor),
                )),
                SizedBox(width: 40.w),
                const Icon(
                  Icons.arrow_forward_ios,
                  size: 14,
                ),
              ]),
        ),
        onTap: () async {
          var result = await Get.toNamed("/device/settings/countries");
          if (result["code"] != null) {
            logic.setCountry(result["name"], result["code"]);
          }
        },
      ),
    );
  }
}
